package com.lry.basic.aop.cglib.classs;

import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Enhancer;
//jdk动态代理：$proxy entends Proxy implments 接口，使用反射，代码拼装+comPiler编译成class
//cglib动态代理：生成三个增强类，使用继承方式，使用asm技术，使用super.方法名直接调用目标方法
//总体来说创建时jdk快于cglib，执行时cglib快于jdk
//https://www.cnblogs.com/monkey0307/p/8328821.html
public class TestCglib {
    public static void main(String[] args) {
        UserService userService = new UserService();
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY,"./");
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(UserService.class);
        enhancer.setCallback(new UserServiceInterceptor(userService));

        userService = (UserService) enhancer.create();

        userService.select();


        userService.finalSelect1();
    }
}
